﻿using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using PMS.SANY.Util;

namespace PMS.SANY.Entity
{
    /// <summary>
    /// 组件
    /// </summary>
    public partial class Component : BusEntity
    {
        /// <summary>
        /// 工序编号
        /// </summary>
        public string OprSequenceId { set; get; }

        /// <summary>
        /// 预留号
        /// </summary>
        public string ReserveNo { set; get; }

        /// <summary>
        /// 预留行项目号
        /// </summary>
        public string ReserveLineNo { set; get; }

        /// <summary>
        /// 组件物料
        /// </summary>
        public string MaterialNo { set; get; }

        /// <summary>
        /// 组件物料描述
        /// </summary>
        public string MaterialName { set; get; }

        /// <summary>
        /// 组件物料简码
        /// </summary>
        public string MaterialAlias { set; get; }

        /// <summary>
        /// 组件数量
        /// </summary>
        public decimal Quantity { set; get; }

        /// <summary>
        /// 单位
        /// </summary>
        public string Unit { set; get; }

        /// <summary>
        /// 预留参数1
        /// </summary>
        public string paramRsrv1 { set; get; }

        /// <summary>
        /// 预留参数2
        /// </summary>
        public string paramRsrv2 { set; get; }

        /// <summary>
        /// 预留参数3
        /// </summary>
        public string paramRsrv3 { set; get; }

        /// <summary>
        /// 预留参数4
        /// </summary>
        public string paramRsrv4 { set; get; }

        /// <summary>
        /// 预留参数5
        /// </summary>
        public string paramRsrv5 { set; get; }
    }

    public partial class Component : BusEntity
    {
        public virtual OprSequence Sequence { set; get; }
    }

    /// <summary>
    /// 实体配置
    /// OnModelCreating
    /// </summary>
    public class ComponentTypeConfig : BusEntityTypeConfig<Component>, IEntityTypeConfiguration<Component>
    {
        public override void Configure(EntityTypeBuilder<Component> builder)
        {
            base.Configure(builder);

            #region 主外键关系
            builder.HasOne(p => p.Sequence).WithMany(p => p.Components).HasForeignKey(p => p.OprSequenceId);
            #endregion

            #region 字段属性:最大长度,是否必需,默认值
            builder.Property(p => p.OprSequenceId).HasMaxLength(50).IsRequired();
            builder.Property(p => p.ReserveNo).HasMaxLength(40).IsRequired();
            builder.Property(p => p.ReserveLineNo).HasMaxLength(40).IsRequired();
            builder.Property(p => p.MaterialNo).HasMaxLength(36).IsRequired();
            builder.Property(p => p.MaterialName).HasMaxLength(300);
            builder.Property(p => p.MaterialAlias).HasMaxLength(40);
            builder.Property(p => p.Quantity).IsRequired();
            builder.Property(p => p.Unit).HasMaxLength(20).IsRequired();
            builder.Property(p => p.paramRsrv1).HasMaxLength(64);
            builder.Property(p => p.paramRsrv2).HasMaxLength(64);
            builder.Property(p => p.paramRsrv3).HasMaxLength(64);
            builder.Property(p => p.paramRsrv4).HasMaxLength(64);
            builder.Property(p => p.paramRsrv5).HasMaxLength(64);
            #endregion

            #region 备注
            builder.HasComment("组件");

            builder.Property(p => p.ReserveNo).HasComment("预留号");
            builder.Property(p => p.ReserveLineNo).HasComment("预留行项目号");
            builder.Property(p => p.MaterialNo).HasComment("组件物料");
            builder.Property(p => p.MaterialName).HasComment("组件物料描述");
            builder.Property(p => p.MaterialAlias).HasComment("组件物料简码");
            builder.Property(p => p.Quantity).HasComment("组件数量");
            builder.Property(p => p.Unit).HasComment("单位");
            builder.Property(p => p.paramRsrv1).HasComment("预留参数1");
            builder.Property(p => p.paramRsrv2).HasComment("预留参数2");
            builder.Property(p => p.paramRsrv3).HasComment("预留参数3");
            builder.Property(p => p.paramRsrv4).HasComment("预留参数4");
            builder.Property(p => p.paramRsrv5).HasComment("预留参数5");
            #endregion

            #region 种子数据
            #endregion
        }
    }
}
